variable_list = ["Divergence", "Fraction of cloud cover", "Geopotential", "Ozone mass mixing ratio",
                 "Potential vorticity", "Relative humidity", "Specific cloud ice water content",
                 "Specific cloud liquid water content", "Specific humidity", "Specific rain water content",
                 "Specific snow water content", "Temperature", "U-component of wind", "V-component of wind",
                 "Vertical velocity", "Vorticity (relative)"]
variable_name2id = {"Divergence": 0, "Fraction of cloud cover": 1, "Geopotential": 2,
                    "Ozone mass mixing ratio": 3, "Potential vorticity": 4, "Relative humidity": 5,
                    "Specific cloud ice water content": 6, "Specific cloud liquid water content": 7,
                    "Specific humidity": 8, "Specific rain water content": 9, "Specific snow water content": 10,
                    "Temperature": 11, "U-component of wind": 12, "V-component of wind": 13, "Vertical velocity": 14,
                    "Vorticity (relative)": 15}

pressure_level_list = ["1", "2", "3", "5", "7", "10", "20", "30", "50", "70", "100", "125", "150", "175",
                       "200", "225", "250", "300", "350", "400", "450", "500", "550", "600", "650", "700",
                       "750", "775", "800", "825", "850", "875", "900", "925", "950", "975", "1000"]
pressure_name2id = {"1": 0, "2": 1, "3": 2, "5": 3, "7": 4, "10": 5, "20": 6, "30": 7, "50": 8, "70": 9,
                    "100": 10, "125": 11, "150": 12, "175": 13, "200": 14, "225": 15, "250": 16, "300": 17,
                    "350": 18, "400": 19, "450": 20, "500": 21, "550": 22, "600": 23, "650": 24, "700": 25,
                    "750": 26, "775": 27, "800": 28, "825": 29, "850": 30, "875": 31, "900": 32, "925": 33,
                    "950": 34, "975": 35, "1000": 36}

# 3 days
timestamp_align = 3 * 24 * 3600


def get_series_key(variable: str, pressure_level: str, timestamp: int) -> bytes:
    result = bytes([variable_name2id[variable], pressure_name2id[pressure_level]])
    result += ((timestamp - timestamp % timestamp_align).to_bytes(4, byteorder='little'))
    return result


def get_series_key_by_id(variable: int, pressure_level: int, timestamp: int) -> bytes:
    result = bytes([variable, pressure_level])
    result += ((timestamp - timestamp % timestamp_align).to_bytes(4, byteorder='little'))
    return result


if __name__ == '__main__':
    key = get_series_key("Temperature", "1", 283996800)
    pass
